#pragma once
#ifndef M6502_H
#define M6502_H

////////////////////////////////////////////////////////////////////////////////////////////////////

#include "Commons.h"
#include <map>
#include <iostream>

////////////////////////////////////////////////////////////////////////////////////////////////////

class M6502 {
    public:
                            M6502           ();
        virtual             ~M6502          ();
        unsigned char       Fetch           ();
        int                 Execute         ( unsigned char );
        void                HandleNMI       ();

    // Setters
        void                SetPC           ( unsigned short value )                            { m_PC.W = value; }
        void                SetRead         ( unsigned char (*value)(unsigned short) )          { m_Read = value; }
        void                SetWrite        ( void (*value)(unsigned short, unsigned char) )    { m_Write = value; }

    private:
        unsigned char       JoinFlags       ()const;
        void                StackPush       ( unsigned char );
        unsigned char       StackPop        ();
        unsigned short      SolveAddress    ( int );

        M6502_REGISTERS     m_Reg;
        PAIR_REGISTER       m_PC;
        unsigned char       m_SP;
        M6502_FLAGS         m_Flag;
        int                 m_Cycles;
        unsigned char       ( *m_Read )     ( unsigned short );
        void                ( *m_Write )    ( unsigned short, unsigned char );
};

////////////////////////////////////////////////////////////////////////////////////////////////////

#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
